#pragma once
#include <pthread.h>
#include <iostream>
#include <string>
//本hpp作用是封装一下锁,让锁可以自动加锁和解锁，和 smart pointer一个设计理念

class ProtectResourse
{
public:
    ProtectResourse(pthread_mutex_t* pmutex)
        : _pmutex(pmutex)
    {
        pthread_mutex_lock(_pmutex);
    }
    ~ProtectResourse()
    {
        pthread_mutex_unlock(_pmutex);
    }
private:
    pthread_mutex_t* _pmutex;
};